package com.itheima.inetaddress;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class Demo03 {
    public static void main(String[] args) throws IOException {
      //创建码头
        DatagramSocket ds = new DatagramSocket(1000);
        //创建小箱子
        byte[] bytes = new byte[1024];
        //创建大箱子
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
        //装数据
        ds.receive(dp);
        //拆数据
        byte[] data = dp.getData();
        int length = dp.getLength();

        //打印数据
        System.out.println(new String(data,0,length));

        //释放资源
        ds.close();


    }
}
